﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace AssetService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class AssetService : IAssetService
    {
        Utilities util = new Utilities();

        public AssetService()
        {
            
        }

        public Model.User Login(string Username, string Password)
        {
            Model.User user = new Model.User(Username, Password);

            if (user.UserID > 0) // user exists in db
            {
                //user.Username = Username;
                //user.Password = Password;
                
                return user;
            }
            else // user doesn't exist in db
            {
                return null;
            }
        }

        public DataTable GetMetaData(int UserID)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@UserID", UserID)
            };
            DataTable dt = util.ReadData("spGetMetadata", parameters);
            return dt;
        }

        public DataTable GetAssets(int UserID, string MetaData)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@UserID", UserID),
                new SqlParameter("@Metadata", MetaData)
            };
            DataTable dt = util.ReadData("spGetAssets", parameters);
            return dt;
        }

        public DataTable GetAssetDetails(int AssetID)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@pkAssetID", AssetID)
        };
            DataTable dt = util.ReadData("spGetAssetDetails", parameters);
            return dt;
        }

        public DataTable GetPurchaseDetails(int AssetID)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@fkAssetID", AssetID)
            };
            DataTable dt = util.ReadData("spGetPurchaseDetails", parameters);
            return dt;
        }

        public DataTable GetScheduleDetails(int AssetID)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@fkAssetID", AssetID)
            };
            DataTable dt = util.ReadData("spGetScheduleDetails", parameters);
            return dt;
        }

        public DataTable GetServiceDetails(int AssetID)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@fkAssetID", AssetID)
            };
            DataTable dt = util.ReadData("spGetServiceDetails", parameters);
            return dt;
        }

        public DataTable GetWarrantyDetails(int AssetID)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@fkAssetID", AssetID)
            };
            DataTable dt = util.ReadData("spGetWarrantyDetails", parameters);
            return dt;
        }

        //public bool Register(string Username, string Password)
        //{
        //    return false;
        //    //return new Model.User(Username, Password);
        //}
    }
}